package com.supergdtop.www.run.tools;

import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;

/**
 * 改变字体工具类
 * <p/>
 * Created by OJH on 2016/9/10.
 */
public class TextTools {


    /**
     * 改变字符串的个别字体大小
     *
     * @param text  字符串
     * @param start 开始位置 从0开始
     * @param end   结束位置
     * @param size  大小
     * @return
     */
    public static SpannableString changeTextSize(String text, int start, int end, float size) {
        SpannableString spannableString = new SpannableString(text);
        spannableString.setSpan(new AbsoluteSizeSpan((int) size), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    /**
     * 改变字符串的个别字体颜色
     *
     * @param text  字符串
     * @param start 开始位置 从0开始
     * @param end   结束位置
     * @param color 颜色
     * @return
     */
    public static SpannableString changeTextColor(String text, int start, int end, int color) {
        SpannableString spannableString = new SpannableString(text);
        spannableString.setSpan(new ForegroundColorSpan(color), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    public static String hideIdCardText(String text) {
        if (text != null && text.length() > 7) {
            StringBuilder stringBuilder = new StringBuilder(text);
            stringBuilder.replace(3, text.length() - 3, "*******");
            return stringBuilder.toString();
        } else {
            return text;
        }
    }
}
